package com.sunye.rabbit_mq_delay;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

// 延时取消订单消息队列
@Configuration
public class OrderCancelMqConfig {
    @Bean
    public Exchange orderCancelExchange() {
        HashMap<String, Object> map = new HashMap<>();
        map.put("x-delayed-type", "direct");
        return new CustomExchange(MQCont.EXCHANGE_DIRECT_ORDER_CANCEL, "x-delayed-message", true, false, map);
    }
    @Bean
    public Queue orderCancelQueue() {
        return QueueBuilder.durable(MQCont.QUEUE_ORDER_CANCEL).build();
    }
    @Bean
    public Binding bindingOrderCancelExchangeToOrderCancelQueue(@Autowired Exchange orderCancelExchange,
                                                                @Autowired Queue orderCancelQueue
    ) {
        return  BindingBuilder.bind(orderCancelQueue).to(orderCancelExchange).with(MQCont.ROUTINGKEY_ORDER_CANCEL).noargs();
    }
}
